home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_unary.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  2KB  |  67 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Test compiler changes for unary ops (+, -, ~) introduced in Python 2.2'''
  5. import unittest
  6. from test.test_support import run_unittest, have_unicode
  7.  
  8. class UnaryOpTestCase(unittest.TestCase):
  9.     
  10.     def test_negative(self):
  11.         self.assert_(-2 == 0 - 2)
  12.         self.assert_(-0 == 0)
  13.         self.assert_(--2 == 2)
  14.         self.assert_(-0x2L == 0 - 0x2L)
  15.         self.assert_(-2.0 == 0 - 2.0)
  16.         self.assert_((0.0+-2.0j) == 0 - (0.0+2.0j))
  17.  
  18.     
  19.     def test_positive(self):
  20.         self.assert_(2 == 2)
  21.         self.assert_(0 == 0)
  22.         self.assert_(+2 == 2)
  23.         self.assert_(0x2L == 0x2L)
  24.         self.assert_(2.0 == 2.0)
  25.         self.assert_((0.0+2.0j) == (0.0+2.0j))
  26.  
  27.     
  28.     def test_invert(self):
  29.         self.assert_(-2 == 0 - 2)
  30.         self.assert_(-0 == 0)
  31.         self.assert_(--2 == 2)
  32.         self.assert_(-0x2L == 0 - 0x2L)
  33.  
  34.     
  35.     def test_no_overflow(self):
  36.         nines = '9' * 32
  37.         self.assert_(eval('+' + nines) == eval('+' + nines + 'L'))
  38.         self.assert_(eval('-' + nines) == eval('-' + nines + 'L'))
  39.         self.assert_(eval('~' + nines) == eval('~' + nines + 'L'))
  40.  
  41.     
  42.     def test_negation_of_exponentiation(self):
  43.         self.assertEqual(-2 ** 3, -8)
  44.         self.assertEqual(-2 ** 3, -8)
  45.         self.assertEqual(-2 ** 4, -16)
  46.         self.assertEqual(-2 ** 4, 16)
  47.  
  48.     
  49.     def test_bad_types(self):
  50.         for op in ('+', '-', '~'):
  51.             self.assertRaises(TypeError, eval, op + "'a'")
  52.             if have_unicode:
  53.                 self.assertRaises(TypeError, eval, op + "u'a'")
  54.                 continue
  55.         
  56.         self.assertRaises(TypeError, eval, '~2j')
  57.         self.assertRaises(TypeError, eval, '~2.0')
  58.  
  59.  
  60.  
  61. def test_main():
  62.     run_unittest(UnaryOpTestCase)
  63.  
  64. if __name__ == '__main__':
  65.     test_main()
  66.  
  67.